<script setup lang="ts">
import type { CSSProperties } from 'vue'

defineProps<{
  checked: boolean,
  style?: CSSProperties
}>()

const emit = defineEmits(['change'])
</script>

<template>
  <view v-if="checked" :class="['box', 'checked']" @click="emit('change')" :style="style">
    <view class="icon">
      <image src="../static/icons/check.png" />
    </view>
  </view>

  <view v-else class="box" @click="emit('change')" :style="style">
    <view class="icon">
      <image src="../static/icons/check.png" />
    </view>
  </view>
</template>

<style scoped lang="scss">
.box {
  width: 30rpx;
  height: 30rpx;
  border-radius: 10rpx;
  border: 2rpx solid $uni-primary;
  display: flex;
  justify-content: center;
  align-items: center;

  .icon {
    opacity: 0;
  }
}

.checked {
  background-color: $uni-primary;

  .icon {
    opacity: 1;
  }
}

.icon {
  width: 20rpx;
  height: 20rpx;
  display: flex;
  justify-content: center;
  align-items: center;

  image {
    width: 100%;
    height: 100%;
  }
}
</style>
